<?php

/**
 * 关于管理
 * @author administrator
 *
 */
class aboutManage extends CControllerManageBase {

	private $_aboutType = array(
    		array("id"=>1,"a_type"=>"关于我们","a_type_name"=>"about"),
    		array("id"=>2,"a_type"=>"联系我们","a_type_name"=>"contact"),
    		array("id"=>3,"a_type"=>"加入我们","a_type_name"=>"join_us"),
    		array("id"=>4,"a_type"=>"法律声明","a_type_name"=>"legal_notices"),
    		array("id"=>5,"a_type"=>"服务协议","a_type_name"=>"services_agreement"),
    		array("id"=>6,"a_type"=>"充值协议","a_type_name"=>"recharge_agreement"),
    		array("id"=>7,"a_type"=>"商务合作","a_type_name"=>"cooperation"),
    		array("id"=>8,"a_type"=>"会员体系","a_type_name"=>"member_info"),
    		array("id"=>9,"a_type"=>"帮助中心","a_type_name"=>"help"),
    		array("id"=>10,"a_type"=>"新手入门","a_type_name"=>"new_member"),
    		array("id"=>11,"a_type"=>"友情链接","a_type_name"=>"links"),
    		array("id"=>12,"a_type"=>"意见反馈","a_type_name"=>"question"),
    	);
    	
    public function show(){
    	$model = new aboutModel();
		$list = $model->selectDataSetByWhere("","a_id,a_type");

		foreach($this->_aboutType as $item)
		{
			$isExists = false;
			foreach($list as $v)
			{
				if($item["id"]==$v["a_id"])
				{
					$isExists = true;
					break;
				}
			}
			if(!$isExists)
			{
				$list[] = array("a_id"=>$item["id"],"a_type"=>$item["a_type"]);
			}
		}

		$this->setMenu("关于我们管理");
		$this->render("about/list",array("list"=>$list));
    }

    public function edit(){
        $model = new aboutModel();
        $id = $this->getRequestData("id","GET");
        
        $aboutInfo = $model->selectById($id);
        if($_POST){
        	$arr["a_id"] = $id;
			$arr['a_content'] = $this->getRequestData('txt_content',"POST","",false);

			if($aboutInfo)
			{
				$iRtn = $model->updateByPkId($arr);
			}
			else{
				foreach($this->_aboutType as $item)
				{
					if($item["id"]==$id)
					{
						$arr["a_type"] = $item["a_type"];
						$arr["a_type_ename"] = $item["a_type_name"];
					}
				}
				$arr["create_time"] = date("Y-m-d H:i:s");
				$iRtn = $model->insert($arr,true,"",false);
			}
			if($iRtn !== false){
				$this->sysMsg("保存成功",0,array(array('text'=>'返回列表','href'=>$this->_manageDomain.'aboutManage/show')));
			}else{
				$this->sysMsg("保存失败",1);
			}
        }
        
        if(!$aboutInfo)
        {
        	$content = "";
        	foreach($this->_aboutType as $item)
			{
				if($item["id"]==$id)
				$aboutInfo["a_type"] = $item["a_type"];
			}
        }
        else{
        	$content = stripslashes($aboutInfo['a_content']);
        }

        $this->setJsFile(array("/kindeditor/kindeditor-min.js", "/kindeditor/lang/zh_CN.js"));
        $this->setJsBlock("var editor;
        KindEditor.ready(function(K) {
                editor = K.create('#txt_content');
        });");

        $this->setMenu(array(
            array('text'=>'关于我们管理','href'=>$this->_manageDomain.'aboutManage/show'),
            array('text'=>"[".$aboutInfo["a_type"]."]修改")
        ));
        $this->render('about/edit',array(
            "a_content"=>$content
        ));
    }
}

?>
